﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using YiNing.Tools;
using YiNing.UI.Forms;

namespace Lixun
{
    public partial class Setting : DarkForm
    {
        BaseParameters baseParameters = new BaseParameters();
        Parameters1 parameters1 = new Parameters1();
        Parameters2 parameters2 = new Parameters2();
        string f1 = "baseParameters.zyn", f2 = "parameters1.zyn", f3 = "parameters2.zyn";
        public Setting(BaseParameters bP, Parameters1 p1, Parameters2 p2)
        {
            InitializeComponent();
            baseParameters = bP;
            parameters1 = p1;
            parameters2 = p2;
            propertyGrid1.SelectedObject = baseParameters;
            propertyGrid2.SelectedObject = parameters1;
            propertyGrid3.SelectedObject = parameters2;
            propertyGrid1.SelectedObjectsChanged += PropertyGrid1_SelectedObjectsChanged;
            propertyGrid2.SelectedObjectsChanged += PropertyGrid2_SelectedObjectsChanged;
            propertyGrid3.SelectedObjectsChanged += PropertyGrid3_SelectedObjectsChanged; ;
        }

        private void PropertyGrid3_SelectedObjectsChanged(object sender, EventArgs e)
        {

            parameters2 = sender as Parameters2;
        }

        private void PropertyGrid2_SelectedObjectsChanged(object sender, EventArgs e)
        {
            parameters1 = sender as Parameters1;
        }

        private void PropertyGrid1_SelectedObjectsChanged(object sender, EventArgs e)
        {
            baseParameters = sender as BaseParameters;
        }

        private void dbtnSave_Click(object sender, EventArgs e)
        {
            JsonHelper.Serialize(baseParameters, f1);
            JsonHelper.Serialize(parameters1, f2);
            JsonHelper.Serialize(parameters2, f3);
        }
    }
}
